﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace BussinessLayer
{
    public class tblChucvu
    {

        DataLayer.Data odata = new DataLayer.Data();
       
        public DataTable SelectChucvu()
        {
            return odata.view_text("SELECT * FROM chucvu where trangthai='True'");
        }

        public DataTable SelectAllChucvu()
        {
            return odata.view_text("SELECT * FROM chucvu");
        }

        public DataTable SelectCVof(int id, string namhoc)
        {
            return odata.view_text("SELECT cv.chucvu_id, cv.chucvu_ten, dvcv.namhoc FROM doanvien AS dv INNER JOIN doanvien_chucvu AS dvcv ON dv.id=dvcv.id INNER JOIN chucvu AS cv ON dvcv.chucvu_id=cv.chucvu_id WHERE dv.id='" + id + "' AND dvcv.namhoc='" + namhoc + "'");
        }
        public void chucvu(int _id, string _ten, string _mieuta,bool _trangthai)
        {
            SqlParameter[] sp = new SqlParameter[4];
            sp[0] = new SqlParameter("@chucvu_id", _id);
            sp[1] = new SqlParameter("@chucvu_ten", _ten);
            sp[2] = new SqlParameter("@chucvu_mieuta", _mieuta);
            sp[3] = new SqlParameter("@trangthai",_trangthai);
            odata.proc_TS("tblChucvu", sp);
        }

        public void Updatetinhtrang(string _id, bool _tinhtrang)
        {
            //SqlParameter[] sp = new SqlParameter[2];
            //sp[0] = new SqlParameter("@chucvu_id", _id);
            //sp[1] = new SqlParameter("@trangthai", _tinhtrang);
            //odata.proc_TS("tblChucvu_updateTinhtrang", sp);
            odata.view_text("UPDATE chucvu SET trangthai='" + _tinhtrang.ToString() + "'");
        }
    }
}
